﻿<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<div class="search_form" style="width:100%">
    <div class="text" style="width:95%">
        <input id="search_txt" name="key" value="" class="keyword ac_input" size="25" maxlength="256"
            accesskey="Enter" />
    </div>
    <div class="button">
        <input type="submit" title="Tìm kiếm" value="" name="search" id="search" onclick="test()" />
    </div>
    <div class="clear">
    </div>
</div>
<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        function test() {
            window.location = encodeURI("/Product/Products?keyword=" + document.getElementById('search_txt').value);
        }
        $(function () {

            $("#search_txt").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: "/Search/Search", type: "POST", dataType: "json",
                        data: { searchText: request.term, maxResults: 10 },
                        success: function (data) {
                            response($.map(data, function (item) {
                                return { label: item.Name, value: item.Name, id: item.View }
                            }))
                        }
                    })
                },
                select: function (event, ui) {
                    if (ui.item) {
                        window.location = encodeURI(ui.item.id);
                    }
                    else {
                        alert("Nothing selected, input was " + this.value);
                    }
                }
            });

        });
    });
</script>
